package com.cskaoyan.controller.backStage;

import com.cskaoyan.model.Category;
import com.cskaoyan.model.vo.BaseRespVO;
import com.cskaoyan.model.vo.CategoryDataVO;
import com.cskaoyan.model.vo.CategoryL1VO;
import com.cskaoyan.model.vo.CategoryVO;
import com.cskaoyan.service.CateGoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：王李轶群
 * @description：商场管理商品类目模块
 * @date ：5/5/22 11:13 PM
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {

    @Autowired
    CateGoryService cateGoryService;

    /**
     * 获取所有商品类目列表
     * @return
     */
    @RequiresPermissions("admin:category:list")
    @RequestMapping("list")
    public BaseRespVO<CategoryDataVO> categoryList(){
        BaseRespVO<CategoryDataVO> categoryList = cateGoryService.getCategoryList();
        return categoryList;
    }

    /**
     * 获取类目value对应label
     * @return
     */
    @RequiresPermissions("admin:category:l1")
    @RequestMapping("l1")
    public BaseRespVO<CategoryL1VO> categoryL1(){
        BaseRespVO<CategoryL1VO> categoryL1 = cateGoryService.getCategoryL1();
        return categoryL1;
    }

    /**
     * 新建类目
     * @param category
     * @return
     */
    @RequiresPermissions("admin:category:create")
    @RequestMapping("create")
    public BaseRespVO<Category> createCategory(@RequestBody Category category){
        BaseRespVO<Category> category1 = cateGoryService.createCategory(category);
        return category1;
    }

    /**
     * 更新类目
     * @param categoryVO
     * @return
     */
    @RequiresPermissions("admin:category:update")
    @RequestMapping("update")
    public BaseRespVO updateCategory(@RequestBody CategoryVO categoryVO){
        BaseRespVO baseRespVO = cateGoryService.updateCategory(categoryVO);
        return baseRespVO;
    }
    @RequiresPermissions("admin:category:delete")
    @RequestMapping("delete")
    public BaseRespVO deleteCaCategory(@RequestBody CategoryVO categoryVO){
        BaseRespVO baseRespVO = cateGoryService.deleteCategory(categoryVO);
        return baseRespVO;
    }
}
